package top.jamsee.dao;

import org.apache.ibatis.annotations.*;
import top.jamsee.entity.Lent_data;
import top.jamsee.entity.RegisterHouse;

import java.util.List;

//房屋登记表dao
public interface RegisterHouseDao {
    // if_owner   buy_or_lent    contact_name      tel             insert_time   description
    public List<RegisterHouse> selectRegisterHouseData();
    //根据id查询是否有此条记录,更新表时使用
    @Select("select count(0) from register_house where id=#{id}")
    public int selectRegisterHouseById(@Param("id") int id);
    //查看买房租房登记表有多少条数据用于分页
    @Select("select count(0) from register_house")
    public int selectRegisterHouseNum();
    //删除买房租房登记表的数据(按id)
    @Delete("delete from register_house where id=#{id}")
    public int deleteRegisterHouseDataById(@Param("id") int id);
    //添加买房租房登记表数据
    @Insert("insert into register_house (if_owner,sell_or_lent,contact_name,tel,insert_time,description)" +
            " values(#{if_owner},#{sell_or_lent},#{contact_name},#{tel},#{insert_time},#{description})")
    public int addRegisterHouseData(RegisterHouse reg);
    //根据名字模糊查询买房租房登记表
    @Select("SELECT * FROM `register_house` where contact_name LIKE CONCAT('%',#{contact_name},'%')")
    public List<RegisterHouse> selectRegisterHouseByData(@Param("contact_name") String contact_name );
    //模糊查询买房租房登记表的所有数量方便后续分页
    @Select("SELECT count(0) FROM `register_house` where contact_name LIKE CONCAT('%',#{contact_name},'%')")
    public int selectRegisterHouseByNum(@Param("contact_name") String contact_name);
    //更新买房租房登记表根据id
    @Update("Update register_house set " +
            "if_owner=#{if_owner},buy_or_lent=#{buy_or_lent},contact_name=#{contact_name},tel=#{tel}," +
            "insert_time=#{insert_time},description=#{description}  where id=#{id}")
    public int upDateRegisterHouseById(RegisterHouse registerHouse);



}
